{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "sys.path.append(r'D:\\codeproject\\data-process')\n",
    "from tqdm.notebook import tqdm\n",
    "import random\n",
    "import ast\n",
    "# 确保 pandas 的 apply 方法可以与 tqdm 一起使用\n",
    "import glob\n",
    "import os\n",
    "from pathlib import Path\n",
    "import pandas as pd\n",
    "tqdm.pandas()\n",
    "import numpy as np\n",
    "import re\n",
    "from datetime import datetime, timedelta\n",
    "from data_deal.function import get_stage_hr, get_stage_rr,rpe_get\n",
    "\n",
    "# 定义源路径和目标路径\n",
    "long_term_deal_path = r'D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1001\\data\\1selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1001\\data\\43selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1001\\data\\44selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1001\\data\\47selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1001\\data\\7selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1001\\rrdata\\1selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1001\\rrdata\\43selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1001\\rrdata\\44selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1001\\rrdata\\47selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1002\\data\\13selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1002\\data\\21selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1002\\data\\29selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1002\\data\\30selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1002\\data\\42selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1002\\data\\47selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1002\\rrdata\\13selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1002\\rrdata\\21selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1002\\rrdata\\29selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1002\\rrdata\\30selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1002\\rrdata\\42selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1002\\rrdata\\47selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\data\\0selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\data\\18selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\data\\2selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\data\\3selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\data\\42selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\data\\43selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\data\\44selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\data\\45selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\data\\46selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\data\\47selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\data\\48selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\data\\49selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\data\\4selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\data\\50selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\data\\51selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\data\\52selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\data\\53selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\data\\5selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\data\\6selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\data\\7selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\data\\8selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\data\\9selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\rrdata\\18selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\rrdata\\42selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\rrdata\\43selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\rrdata\\44selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\rrdata\\45selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\rrdata\\46selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\rrdata\\47selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\rrdata\\48selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\rrdata\\49selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\rrdata\\50selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\rrdata\\51selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\rrdata\\52selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\rrdata\\53selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1008\\data\\10selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1008\\data\\19selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1008\\data\\29selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1008\\data\\2selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1008\\data\\3selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1008\\rrdata\\10selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1008\\rrdata\\19selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1008\\rrdata\\29selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1008\\rrdata\\2selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1008\\rrdata\\3selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1009\\data\\0selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1009\\data\\0selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1009\\data\\15selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1009\\data\\1selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1009\\data\\2selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1009\\data\\40selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1009\\data\\46selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1009\\data\\48selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1009\\data\\53selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1009\\rrdata\\0selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1009\\rrdata\\15selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1009\\rrdata\\1selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1009\\rrdata\\2selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1009\\rrdata\\40selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1009\\rrdata\\46selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1009\\rrdata\\48selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1009\\rrdata\\53selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\data\\13selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\data\\14selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\data\\15selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\data\\16selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\data\\17selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\data\\18selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\data\\19selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\data\\20selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\data\\21selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\data\\22selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\data\\23selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\data\\24selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\data\\25selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\data\\33selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\data\\37selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\data\\38selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\data\\40selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\data\\41selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\data\\42selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\data\\43selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\data\\44selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\data\\62selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\data\\6selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\data\\70selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\data\\71selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\data\\72selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\data\\73selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\13selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\14selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\15selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\16selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\17selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\18selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\19selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\20selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\21selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\22selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\23selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\24selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\25selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\33selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\37selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\38selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\40selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\41selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\42selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\43selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\44selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\62selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\70selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\71selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\72selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\73selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1013\\data\\10selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1013\\data\\11selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1016\\data\\24selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1016\\rrdata\\24selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1018\\data\\1selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1018\\data\\27selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1018\\rrdata\\1selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1018\\rrdata\\27selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1025\\data\\15selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1025\\data\\36selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1025\\rrdata\\15selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1025\\rrdata\\36selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1054\\data\\18selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1054\\data\\23selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1054\\rrdata\\18selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1054\\rrdata\\23selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\10selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\11selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\11selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\19selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\22selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\23selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\24selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\25selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\26selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\27selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\28selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\29selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\30selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\31selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\32selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\33selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\34selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\35selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\36selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\37selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\38selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\39selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\3selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\40selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\41selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\42selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\43selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\44selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\45selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\46selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\47selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\48selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\49selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\4selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\50selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\51selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\52selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\53selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\54selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\55selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\56selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\57selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\58selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\5selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\6selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\7selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\7selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\8selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\data\\9selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\11selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\19selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\22selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\23selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\24selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\25selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\26selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\27selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\28selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\29selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\30selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\31selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\32selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\33selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\34selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\35selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\36selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\37selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\38selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\39selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\40selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\41selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\42selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\43selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\44selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\45selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\46selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\47selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\48selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\49selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\50selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\51selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\52selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\53selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\54selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\55selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\56selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\57selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\58selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\7selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1077\\data\\0selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1077\\data\\1selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1077\\data\\2selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1077\\data\\3selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1077\\data\\4selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1078\\data\\31selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1078\\data\\32selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1078\\data\\33selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1078\\data\\34selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1078\\data\\35selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1078\\data\\53selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1078\\data\\7selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1078\\rrdata\\31selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1078\\rrdata\\32selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1078\\rrdata\\33selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1078\\rrdata\\34selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1078\\rrdata\\35selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1078\\rrdata\\53selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1081\\data\\0selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1081\\data\\19selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1081\\data\\35selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1081\\rrdata\\19selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1081\\rrdata\\35selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1089\\data\\28selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1089\\rrdata\\28selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1094\\data\\0selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1094\\data\\1selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1094\\rrdata\\0selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1094\\rrdata\\1selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1104\\data\\8selectrun.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1110\\data\\16selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1110\\data\\30selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1110\\data\\32selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1110\\data\\33selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1110\\data\\34selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1110\\data\\36selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1110\\rrdata\\16selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1110\\rrdata\\30selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1110\\rrdata\\32selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1110\\rrdata\\33selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1110\\rrdata\\34selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1110\\rrdata\\36selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1112\\data\\32selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1112\\rrdata\\32selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1120\\data\\1selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1120\\rrdata\\1selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1121\\data\\10selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1121\\data\\22selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1121\\rrdata\\10selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1121\\rrdata\\22selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1137\\data\\3selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1137\\data\\43selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1137\\data\\7selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1137\\rrdata\\3selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1137\\rrdata\\43selectresting.csv\n",
      "已删除文件: D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1137\\rrdata\\7selectresting.csv\n"
     ]
    }
   ],
   "source": [
    "#删除D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar中文件名含有select的文件\n",
    "\n",
    "def delete_files_containing_select(root_dir):\n",
    "    for root, dirs, files in os.walk(root_dir):\n",
    "        for file in files:\n",
    "            if \"select\" in file:\n",
    "                file_path = os.path.join(root, file)\n",
    "                try:\n",
    "                    os.remove(file_path)  # 直接删除文件，如果是文件夹会报错，所以先判断是文件\n",
    "                    print(f\"已删除文件: {file_path}\")\n",
    "                except IsADirectoryError:\n",
    "                    print(f\"{file_path} 是文件夹，不能直接删除，跳过\")\n",
    "                except PermissionError:\n",
    "                    print(f\"没有权限删除 {file_path}，跳过\")\n",
    "\n",
    "\n",
    "root_directory = r\"D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\"\n",
    "delete_files_containing_select(root_directory)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [],
   "source": [
    "file_df=pd.DataFrame(columns=['id'])\n",
    "long_term_user=pd.read_csv(r'D:\\学习&科研\\华为手表项目\\华为数据\\base-data\\gluser.csv')\n",
    "# for index ,row in long_term_user.iterrows():\n",
    "#     id=row['id']\n",
    "# 创建一个包含要处理的id值的Series（这里是[1001, 1002]，可根据实际替换）\n",
    "\n",
    "\n",
    "import pandas as pd\n",
    "from pathlib import Path\n",
    "import os\n",
    "\n",
    "# 创建包含id值的Series\n",
    "id_series = pd.Series(long_term_user['id'].to_list())\n",
    "\n",
    "# 初始化file_df，包含'id'列（可以根据实际需求调整列定义等）\n",
    "file_df = pd.DataFrame(columns=['id'])\n",
    "file_df['id'] = id_series\n",
    "\n",
    "# print(file_df)\n",
    "\n",
    "# 创建包含id值的Series\n",
    "# id_series = pd.Series([1001, 1002])\n",
    "\n",
    "# # 初始化file_df，包含'id'列（可以根据实际需求调整列定义等）\n",
    "# file_df = pd.DataFrame(columns=['id'])\n",
    "# file_df['id'] = id_series\n",
    "\n",
    "\n",
    "# 定义一个函数，用于处理每个id对应的相关路径及文件信息添加到DataFrame的逻辑\n",
    "def process_id(id_value):\n",
    "    data_path = os.path.join(long_term_deal_path, 'polar', str(id_value), 'data')\n",
    "    rrdata_path = os.path.join(long_term_deal_path, 'polar', str(id_value), 'rrdata')\n",
    "\n",
    "    rrdatafile_paths = sorted([str(file) for file in Path(rrdata_path).iterdir() if file.is_file()])\n",
    "    datafile_paths = sorted([str(file) for file in Path(data_path).iterdir() if file.is_file()])\n",
    "    max_length = max(len(rrdatafile_paths), len(datafile_paths))\n",
    "    rrdatafile_paths += [None] * (max_length - len(rrdatafile_paths))  # 可以用其它值填充\n",
    "    datafile_paths += [None] * (max_length - len(datafile_paths))  # 可以用其它值填充\n",
    "    # 创建DataFrame，确保rrdatafile_paths和datafile_paths是单独的列\n",
    "    new_df = pd.DataFrame({'rrdatapath': rrdatafile_paths, 'data_path': datafile_paths})\n",
    "\n",
    "    # 添加id列\n",
    "    new_df['id'] = id_value\n",
    "    \n",
    "    return new_df\n",
    "\n",
    "# 使用apply函数调用process_id函数处理每个id值，并将结果合并到file_df中\n",
    "result_dfs = file_df['id'].apply(process_id).reset_index(drop=True)\n",
    "result_dfs_list = result_dfs.tolist()\n",
    "\n",
    "file_df = pd.concat(result_dfs_list, ignore_index=True)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "# 将result_dfs转换为包含DataFrame的列表，使其符合pd.concat的要求\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "# 使用apply函数调用process_id函数处理每个id值，并将结果合并到file_df中\n",
    "\n",
    "\n",
    "\n",
    "def get_activity_times(file_path):\n",
    "        try:\n",
    "            # 读取 CSV 文件\n",
    "            # df = ecg_deal(file_path)  # 需要你定义这个处理函数\n",
    "            df=pd.read_csv(file_path)\n",
    "\n",
    "            # 提取第一行和最后一行的 ecg_timestamp\n",
    "            start_time = df.iloc[0]['timestamp']\n",
    "            end_time = df.iloc[-1]['timestamp']\n",
    "            # 转换为 pandas datetime 格式\n",
    "            start_time = pd.to_datetime(start_time, unit='ms')\n",
    "            end_time = pd.to_datetime(end_time, unit='ms')\n",
    "            start_time = start_time + timedelta(hours=8)\n",
    "            end_time = end_time + timedelta(hours=8)\n",
    "            return start_time, end_time\n",
    "        except Exception as e:\n",
    "            print(f\"Error processing file {file_path}: {e}\")\n",
    "            return None, None\n",
    "   \n",
    "    # 获取活动开始时间和结束时间，并添加到 DataFrame 中\n",
    "file_df[['polar采集开始', 'polar采集结束']] = file_df['rrdatapath'].apply(get_activity_times).apply(pd.Series)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "def healthtest_path_get(id):\n",
    "    healthtest_path=os.path.join(long_term_deal_path,'healthtest')\n",
    "    #循环healthtest文件夹\n",
    "    for root, dirs, files in os.walk(healthtest_path):\n",
    "        for file in files:\n",
    "            if file.endswith('.csv') and str(id) in file:\n",
    "                return os.path.join(root, file)\n",
    "    return None\n",
    "\n",
    "file_df['healthtest_path']=file_df['id'].apply(healthtest_path_get)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "file_df['singlework_path']=file_df['id'].apply(lambda x:os.path.join(long_term_deal_path,'singlework',str(x)+'_singleworkout.csv'))\n",
    "\n",
    "\n",
    "\n",
    "def get_stateandday(file_name):\n",
    "    day = None\n",
    "    state = None\n",
    "    day = file_name.split('-')[1]\n",
    "    if 'running' in file_name:\n",
    "        state = 'running'\n",
    "    elif 'morning' in file_name:\n",
    "        state = 'morning'\n",
    "    elif 'evening' in file_name:\n",
    "        state = 'evening'\n",
    "    \n",
    "    \n",
    "    else:\n",
    "        day = None\n",
    "        state = None\n",
    "    return day ,state\n",
    "\n",
    "# 使用apply函数结合lambda表达式来处理，将返回的两个值分别赋给对应的列\n",
    "file_df[['day','state']] = file_df['rrdatapath'].apply(lambda x: pd.Series(get_stateandday(x)) if pd.notnull(x) and x != '' else pd.Series([None, None]))\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "8a7abf8d910f4504b6e7e38e497d676b",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "匹配healthtest:   0%|          | 0/1871 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "#匹配对应的healtest\n",
    "\n",
    "def match_kuaice_times(row):\n",
    "    try:\n",
    "        if row['state'] != 'running':\n",
    "\n",
    "            file_start = row['polar采集开始']\n",
    "            \n",
    "            for _, kuaice_row in pd.read_csv(row['healthtest_path']).iterrows():\n",
    "                kuaice_row['time'] = pd.to_datetime(kuaice_row['time'])\n",
    "                kuaice_time = kuaice_row['time']\n",
    "                time_diff = abs((kuaice_time - file_start).total_seconds())\n",
    "                if time_diff <= 20 * 60:\n",
    "                    return pd.Series([kuaice_row['HR'], kuaice_row['HRV']])\n",
    "    except:\n",
    "        return pd.Series([None, None])\n",
    "\n",
    "# 应用函数并将结果存入新的列\n",
    "tqdm.pandas(desc='匹配healthtest')\n",
    "file_df[['healthtest-HR', 'healthtest-HRV']] = file_df.progress_apply(match_kuaice_times, axis=1)\n",
    "file_df['healthtest-type']=file_df['healthtest_path'].apply(lambda x:x.split('-')[1])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "a683e3f15949488c8b5b9f9952b8e883",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "跑步开始时间和结束时间:   0%|          | 0/1871 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "\n",
    "def match_running_times(row):\n",
    "    \n",
    "    try:\n",
    "        file_start = row['polar采集开始']\n",
    "\n",
    "        for _, single_row in pd.read_csv(row['singlework_path']).iterrows():\n",
    "            single_row['活动.测量开始时间']=pd.to_datetime(single_row['活动.测量开始时间'])\n",
    "            single_row['活动.测量结束时间']=pd.to_datetime(single_row['活动.测量结束时间'])\n",
    "            measure_start = single_row['活动.测量开始时间']\n",
    "            measure_end = single_row['活动.测量结束时间']\n",
    "        \n",
    "            # 计算时间差\n",
    "            time_diff = abs((measure_start - file_start).total_seconds())\n",
    "            \n",
    "            # 如果时间差在30分钟以内，则返回测量的开始和结束时间\n",
    "            if time_diff <= 20 * 60:\n",
    "                return pd.Series([measure_start, measure_end])\n",
    "\n",
    "        # 如果没有匹配的时间段，返回 None\n",
    "    except:\n",
    "        return pd.Series([None, None])\n",
    "    return pd.Series([None, None])\n",
    "# 应用函数并将结果存入新的列\n",
    "tqdm.pandas(desc='跑步开始时间和结束时间')\n",
    "file_df[['跑步开始时间', '跑步结束时间']] = file_df.progress_apply(match_running_times, axis=1)\n",
    "\n",
    "running_df = file_df.loc[file_df['state'] == 'running']\n",
    "\n",
    "# 复制为三行，并修改 state 值\n",
    "running_df_1 = running_df.copy()\n",
    "running_df_1['state'] = 'rest_before_running'\n",
    "\n",
    "running_df_2 = running_df.copy()\n",
    "running_df_2['state'] = 'running_running'\n",
    "\n",
    "running_df_3 = running_df.copy()\n",
    "running_df_3['state'] = 'rest_after_running'\n",
    "\n",
    "# 合并生成的三份数据\n",
    "result_df = pd.concat([running_df_1, running_df_2, running_df_3], ignore_index=True)\n",
    "\n",
    "# 删除原始数据中 state 为 'running' 的行\n",
    "file_df = file_df[file_df['state'] != 'running']\n",
    "\n",
    "# 将生成的数据合并回原始 DataFrame\n",
    "file_df = pd.concat([file_df, result_df], ignore_index=True)\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "32215331c9a7461398a0bf7828dacc9e",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "全程rr,hr:   0%|          | 0/2553 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\rrdata\\1007-22-running7044.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1009\\rrdata\\1009-26-running2708.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\1010-35-running6136.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1013\\rrdata\\1013-20-running8314.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1013\\rrdata\\1013-27-running5028.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1013\\rrdata\\1013-34-running2792.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1013\\rrdata\\1013-6-running7575.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1018\\rrdata\\1018-11-running2263.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1025\\rrdata\\1025-12-running9056.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1025\\rrdata\\1025-27-running1931.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1025\\rrdata\\1025-3-running2937.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1025\\rrdata\\1025-5-running5234.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\1073-13-running2786.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1077\\rrdata\\1077-8-running2104.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1078\\rrdata\\1078-12-running9675.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1078\\rrdata\\1078-15-running3905.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1078\\rrdata\\1078-2-running6517.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1078\\rrdata\\1078-7-running5638.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1081\\rrdata\\1081-4-running5329.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1094\\rrdata\\1094-1-running4859.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1094\\rrdata\\1094-3-running2610.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1094\\rrdata\\1094-4-running1924.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1111\\rrdata\\1111-17-running5880.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1111\\rrdata\\1111-28-running7194.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1112\\rrdata\\1112-11-running5831.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1112\\rrdata\\1112-12-running2892.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1112\\rrdata\\1112-19-running3445.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1112\\rrdata\\1112-22-running2305.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1112\\rrdata\\1112-23-running7890.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1112\\rrdata\\1112-26-running4865.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1112\\rrdata\\1112-5-running1089.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1112\\rrdata\\1112-7-running3813.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1117\\rrdata\\1117-17-running9680.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1122\\rrdata\\1122-25-running5165.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1137\\rrdata\\1137-13-running3931.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1137\\rrdata\\1137-4-running8932.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1137\\rrdata\\1137-5-running7340.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\rrdata\\1007-22-running7044.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1009\\rrdata\\1009-26-running2708.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\1010-35-running6136.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1013\\rrdata\\1013-20-running8314.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1013\\rrdata\\1013-27-running5028.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1013\\rrdata\\1013-34-running2792.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1013\\rrdata\\1013-6-running7575.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1018\\rrdata\\1018-11-running2263.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1025\\rrdata\\1025-12-running9056.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1025\\rrdata\\1025-27-running1931.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1025\\rrdata\\1025-3-running2937.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1025\\rrdata\\1025-5-running5234.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\1073-13-running2786.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1077\\rrdata\\1077-8-running2104.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1078\\rrdata\\1078-12-running9675.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1078\\rrdata\\1078-15-running3905.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1078\\rrdata\\1078-2-running6517.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1078\\rrdata\\1078-7-running5638.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1081\\rrdata\\1081-4-running5329.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1094\\rrdata\\1094-1-running4859.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1094\\rrdata\\1094-3-running2610.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1094\\rrdata\\1094-4-running1924.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1111\\rrdata\\1111-17-running5880.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1111\\rrdata\\1111-28-running7194.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1112\\rrdata\\1112-11-running5831.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1112\\rrdata\\1112-12-running2892.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1112\\rrdata\\1112-19-running3445.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1112\\rrdata\\1112-22-running2305.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1112\\rrdata\\1112-23-running7890.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1112\\rrdata\\1112-26-running4865.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1112\\rrdata\\1112-5-running1089.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1112\\rrdata\\1112-7-running3813.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1117\\rrdata\\1117-17-running9680.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1122\\rrdata\\1122-25-running5165.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1137\\rrdata\\1137-13-running3931.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1137\\rrdata\\1137-4-running8932.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1137\\rrdata\\1137-5-running7340.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1007\\rrdata\\1007-22-running7044.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1009\\rrdata\\1009-26-running2708.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1010\\rrdata\\1010-35-running6136.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1013\\rrdata\\1013-20-running8314.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1013\\rrdata\\1013-27-running5028.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1013\\rrdata\\1013-34-running2792.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1013\\rrdata\\1013-6-running7575.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1018\\rrdata\\1018-11-running2263.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1025\\rrdata\\1025-12-running9056.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1025\\rrdata\\1025-27-running1931.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1025\\rrdata\\1025-3-running2937.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1025\\rrdata\\1025-5-running5234.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1073\\rrdata\\1073-13-running2786.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1077\\rrdata\\1077-8-running2104.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1078\\rrdata\\1078-12-running9675.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1078\\rrdata\\1078-15-running3905.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1078\\rrdata\\1078-2-running6517.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1078\\rrdata\\1078-7-running5638.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1081\\rrdata\\1081-4-running5329.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1094\\rrdata\\1094-1-running4859.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1094\\rrdata\\1094-3-running2610.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1094\\rrdata\\1094-4-running1924.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1111\\rrdata\\1111-17-running5880.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1111\\rrdata\\1111-28-running7194.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1112\\rrdata\\1112-11-running5831.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1112\\rrdata\\1112-12-running2892.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1112\\rrdata\\1112-19-running3445.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1112\\rrdata\\1112-22-running2305.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1112\\rrdata\\1112-23-running7890.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1112\\rrdata\\1112-26-running4865.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1112\\rrdata\\1112-5-running1089.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1112\\rrdata\\1112-7-running3813.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1117\\rrdata\\1117-17-running9680.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1122\\rrdata\\1122-25-running5165.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1137\\rrdata\\1137-13-running3931.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1137\\rrdata\\1137-4-running8932.csv: NaTType does not support timestamp\n",
      "error D:\\学习&科研\\华为手表项目\\华为数据\\long_term_deal\\polar\\1137\\rrdata\\1137-5-running7340.csv: NaTType does not support timestamp\n"
     ]
    }
   ],
   "source": [
    "\n",
    "\n",
    "\n",
    "def get_activity_rr(row):\n",
    "    try:\n",
    "        file_path = row['rrdatapath']\n",
    "        df = pd.read_csv(file_path)\n",
    "        df['rr']=df['rr'].apply(lambda x: ast.literal_eval(x))\n",
    "        \n",
    "        rr_list, hr_list = [], []\n",
    "\n",
    "        if row['state'] == 'morning' or row['state'] == 'evening':\n",
    "            rr_list = df['rr'].to_list()\n",
    "            hr_list = pd.to_numeric(df['HR'], errors='coerce').tolist()\n",
    "\n",
    "        elif row['state'] == 'rest_before_running':\n",
    "            \n",
    "            starttime = int(pd.to_datetime(row['polar采集开始']).tz_localize('Asia/Shanghai').timestamp() * 1000)\n",
    "            endtime = int(pd.to_datetime(row['跑步开始时间']).tz_localize('Asia/Shanghai').timestamp() * 1000)\n",
    "            \n",
    "            get_df = df[(df['timestamp'] >= starttime) & (df['timestamp'] <= endtime)]\n",
    "            rr_list = get_df['rr'].to_list()\n",
    "            hr_list = pd.to_numeric(get_df['HR'], errors='coerce').tolist()\n",
    "\n",
    "        elif row['state'] == 'running_running':\n",
    "            starttime = int(pd.to_datetime(row['跑步开始时间']).tz_localize('Asia/Shanghai').timestamp() * 1000)\n",
    "            endtime = int(pd.to_datetime(row['跑步结束时间']).tz_localize('Asia/Shanghai').timestamp() * 1000)\n",
    "            get_df = df[(df['timestamp'] >= starttime) & (df['timestamp'] <= endtime)]\n",
    "            rr_list = get_df['rr'].to_list()\n",
    "            hr_list = pd.to_numeric(get_df['HR'], errors='coerce').tolist()\n",
    "\n",
    "        elif row['state'] == 'rest_after_running':\n",
    "            starttime = int(pd.to_datetime(row['跑步结束时间']).tz_localize('Asia/Shanghai').timestamp() * 1000)\n",
    "            endtime = int(pd.to_datetime(row['polar采集结束']).tz_localize('Asia/Shanghai').timestamp() * 1000)\n",
    "            get_df = df[(df['timestamp'] >= starttime) & (df['timestamp'] <= endtime)]\n",
    "            rr_list = get_df['rr'].to_list()\n",
    "            hr_list = pd.to_numeric(get_df['HR'], errors='coerce').tolist()\n",
    "\n",
    "        # # 扁平化 rr_list（如果它包含子列表）\n",
    "        \n",
    "        flattened_rr_list = [int(item) for sublist in rr_list for item in sublist if item and item.strip().isdigit()]\n",
    "        \n",
    "        # 返回两个列表作为 pd.Series\n",
    "        return pd.Series([flattened_rr_list, hr_list])\n",
    "\n",
    "    except Exception as e:\n",
    "        print(f\"error {file_path}: {e}\")\n",
    "        return pd.Series([[], []])  # 如果发生错误，返回空列表\n",
    "\n",
    "tqdm.pandas(desc='全程rr,hr')\n",
    "file_df[['全程rr', '全程hr']] = file_df.progress_apply(get_activity_rr, axis=1)\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "1e8c2278ddbb4dfdbe44c918ab05f731",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "rpe:   0%|          | 0/2553 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "file_df = file_df.sort_values(by='polar采集开始')\n",
    "\n",
    "\n",
    "def get_rpe(row):\n",
    "    try:\n",
    "   \n",
    "    # ecg = long_term_ecg_deal(file)\n",
    "        ecg=pd.read_csv(row['data_path'],low_memory=False)\n",
    "        \n",
    "\n",
    "        # 获取每列中第一个非'-'的值，如果没有有效值则返回空\n",
    "        psychology_RPE = ecg[ecg['psychology_RPE'] != '-']['psychology_RPE'].unique().tolist()\n",
    "        physiology_RPE = ecg[ecg['physiology_RPE'] != '-']['physiology_RPE'].unique().tolist()\n",
    "        now_RPE = ecg[ecg['now_RPE'] != '-']['now_RPE'].unique().tolist()\n",
    "        train_RPE = ecg[ecg['train_RPE'] != '-']['train_RPE'].unique().tolist()\n",
    "        # print(file)\n",
    "        # print(psychology_RPE,physiology_RPE,now_RPE,train_RPE)\n",
    "        # 返回所有列表组成的一个总列表\n",
    "        \n",
    "        return pd.Series([psychology_RPE, physiology_RPE, now_RPE, train_RPE])\n",
    "    except:\n",
    "        return pd.Series([None, None, None, None])\n",
    "\n",
    "tqdm.pandas(desc='rpe')\n",
    "file_df[['psychology_RPE','physiology_RPE','now_RPE','train_RPE']]=file_df.progress_apply(get_rpe,axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "file_df.to_csv(long_term_deal_path+'\\\\'+'longfile_df.csv',index=False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "MLandDL",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.20"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
